﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Mapa.Master" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="MainContentPlaceHolder" runat="server">
     
      <p>
        <%if ((bool)ViewData["IsAdmin"])
          { %>    
        Cliente: <%= Html.DropDownList("Clientes")%>            
        <%} %>


        Tipo:
        <select id="tipo" name="tipo">
            <option value="0">Seleccionar Tipo</option>
            <option value="1">Unidades</option>
            <option value="2">Grupos</option>
        </select>

        <span id="unidadSpan">
            Unidad: <%: Html.DropDownList("CodigoUnidad","Ver Todas Las Unidades") %>
        </span>

        <span id="grupoSpan">
            Grupo: <%: Html.DropDownList("Grupos", "Ver Todos Los Grupos")%>
        </span>
         
         <span id="mapal">
            Mapa:
        </span>
        
        <select id="mapa" name="mapa">
        
            <option value="0">GoogleMaps</option>
            <option value="1">GoogleMaps Satelite</option>
            <option value="2">Google Earth</option>
        </select>
               
        <input id="btnUnidad" type="button" value="Buscar Unidad" onclick="testtimeout();" />
        <input id="btnGrupo" type="button" value="Buscar Grupo" onclick="testtimeoutGrupo();" />
        <input id="btnUnidadTodas" type="button" value="Buscar Unidades" onclick="testtimeoutTodas();" />
        <input id="btnGrupoTodos" type="button" value="Buscar Grupos" onclick="testtimeoutGrupoTodos();" />

        <%--<span><a id="startelmaps" href="javascript:alert('Presione el botón buscar antes de continuar.')">Startel Maps</a></span>--%>

    </p>
    
    
    <div id="map_canvas" style="width: 100%; height: 100%;">
    </div>

</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="HeadContentPlaceHolder" runat="server">
    
    
    <script type="text/javascript" src="<%= ResolveUrl("~") %>Content/Mapa/dragzoom.js" ></script>

    <script type="text/javascript" language="javascript">
    
       $(function () {
            
            $("#grupoSpan").hide();
            $("#btnGrupo").hide();
            $("#btnUnidad").hide();
             $("#btnGrupoTodos").hide();
            $("#btnUnidadTodas").hide();
             $("#unidadSpan").hide();
              $("#mapa").hide();
               $("#mapal").hide();

            $("#tipo").change(function() {
                if($(this).val() == 2)
                {
                    $("#unidadSpan").hide();
                    $("#grupoSpan").show();
//                    $("#btnGrupoTodos").hide();
//                    $("#btnUnidadTodas").hide();
                }
                else if($(this).val() == 1)
                {
                    $("#unidadSpan").show();
                    $("#grupoSpan").hide();
//                    $("#btnGrupoTodos").hide();
//                    $("#btnUnidadTodas").hide();
                }
                else
                
                {
                
                     $("#unidadSpan").hide();
                    $("#grupoSpan").hide();
                    $("#mapa").hide();
                    $("#mapal").hide();
//                    $("#btnGrupoTodos").hide();
//                    $("#btnUnidadTodas").hide();
//                
                
                
                }
            });


            $("#CodigoUnidad").change(function() {
                if($(this).val() != "")
                {
                  
                  // alert("una");
                     $("#mapa").show();
                     $("#mapal").show();
                    $("#btnUnidad").show();
                    $("#btnUnidadTodas").hide();
                      $("#btnGrupo").hide();
                    $("#btnGrupoTodos").hide();
            
               
                }
               
                
                else
                {
                   
                    //alert("todas");
                     $("#mapa").show();
                     $("#mapal").show();
                     $("#btnUnidad").hide();
                    $("#btnUnidadTodas").show();
                      $("#btnGrupo").hide();
                    $("#btnGrupoTodos").hide();
          
                   
                
                }
            });

            $("#Grupos").change(function() {
                if($(this).val() != "")
                {
                  
                    $("#mapa").show();
                    $("#mapal").show();
                    $("#btnGrupo").show();
                    $("#btnGrupoTodos").hide();
                     $("#btnUnidad").hide();
                    $("#btnUnidadTodas").hide();
               
                }
               
                
                else
                {
                   
                     $("#mapa").show();
                      $("#mapal").show();
                     $("#btnGrupo").hide();
                    $("#btnGrupoTodos").show();
          
                    $("#btnUnidad").hide();
                    $("#btnUnidadTodas").hide();
                
                }
            });

            <%if ((bool)ViewData["IsAdmin"])
              { %>
                $("#Clientes").change(function () {
                    document.location.href = "<%= ResolveUrl("~") %>Mapa/Index/?clienteId=" + $(this).val();                
                });
            <%} %>            
        });
    </script>

<script type="text/javascript">

    //var x = 0;
    var unidadTimer=0;
    var unidadTodasTimer=0;
    var grupoTimer=0;
    var grupoTodosTimer=0;

    function testtimeout() {

        clearTimeout(unidadTodasTimer);
        clearTimeout(grupoTimer);
        clearTimeout(grupoTodosTimer);

        //alert($("#mapa").val());
        //G_SATELLITE_3D_MAP
       
        GetLatLongTrack($("#mapa").val());



        var tmp = $("#mapa").val();
        var tim = "";

        //alert(tmp);

        if (tmp == 0) {

            tim = "20000";


        }
        else if (tmp == 1) {

            tim = "30000";


        }
        else 
        {

            tim = "55000";
        
        }


        unidadTimer = setTimeout("testtimeout()", tim);

    }

    function testtimeoutTodas() {

        clearTimeout(unidadTimer);
        clearTimeout(grupoTimer);
        clearTimeout(grupoTodosTimer);

        GetLatLongTrackTodas($("#mapa").val());


        unidadTodasTimer=setTimeout("testtimeoutTodas()", 180000);
       

    }

    function testtimeoutGrupo() {

        clearTimeout(unidadTimer);
        clearTimeout(unidadTodasTimer);
        clearTimeout(grupoTodosTimer);

        GetLatLongTrackGrupo($("#mapa").val());


        grupoTimer=setTimeout("testtimeoutGrupo()", 30000);

    }

    function testtimeoutGrupoTodos() {
        //x = x + 1;
        //alert(" value of x is - " + x);
        clearTimeout(unidadTimer);
        clearTimeout(grupoTimer);
        clearTimeout(unidadTodasTimer);



        GetLatLongTrackGrupo($("#mapa").val());


        grupoTodosTimer=setTimeout("testtimeoutGrupoTodos()", 180000);

    }

    </script>
    <script type="text/javascript">

           
        function initialize() {
        //alert("de una");
            $.ajax({
                type: "POST",
                url: "<%= ResolveUrl("~") %>Mapa/index",
//                data: 'id=' + $("#Grupos").val(),
                dataType: "json",
                cache: false,
                success: function (response) {
                    //alert("entre suscces");

                    if (GBrowserIsCompatible()) {
                        var map = new GMap2(document.getElementById("map_canvas"));
                        //map.setMapType(G_HYBRID_MAP);
                        map.addMapType(G_SATELLITE_3D_MAP);
                        map.addControl(new DragZoomControl());
                        var baseIcon = new GIcon();
                        baseIcon.iconSize = new GSize(40, 60);
                        baseIcon.shadowSize = new GSize(40, 60);
                        baseIcon.iconAnchor = new GPoint(40, 60);
                        baseIcon.infoWindowAnchor = new GPoint(16, 0);
                        //var edificio = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/CabrioletRedblanco.png", null, "<%= ResolveUrl("~") %>Content/Images/CabrioletRedblancos.png");
                        var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/Flechas-180.gif", null, "<%= ResolveUrl("~") %>Content/Images/Flechas-180s.gif");
                        
                        //var center = new GLatLng(data[0], data[1]);
                        var center0=new GLatLng();
                        var pol = new Array();
                        var contador = 0;

                         $.each(response, function(i, data) {

                            if( contador == 0 ) {
                                $('#startelmaps').attr('href', '<%= ResolveUrl("~") %>Mapa/Startelmaps/?lon=' + data.Longitud + 
                                    '&lat=' + data.Latitud + '&nom=' + data.NombreUnidad + 
                                    '&pla=' + data.PlacaUnidad + '&vel=' + data.Velocidad + 
                                    '&fch=' + data.Fecha);
                            }

                            contador ++;

                           //alert (center1);
                            var center = new GLatLng(data.Latitud, data.Longitud);
                            var center0=center;
                           
                            if(data.Grados==0)
                        {
                            sentido="N";

                            if (data.Velocidad>5)
                            {
                                var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/cvFlecha/Encendido.png", null, "<%= ResolveUrl("~") %>Content/Images/cvFlecha/Encendido.png");
                            }
                             else if(data.Evento!=1)
                            {
                            
                                var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/emerFlecha/Emergencia.png", null, "<%= ResolveUrl("~") %>Content/Images/emerFlecha/Emergencia.png");
                            
                            }
                            else
                            {
                                var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/stopFlecha/Stop.png", null, "<%= ResolveUrl("~") %>Content/Images/stopFlecha/Stop.png");
                            }
                        }
                        
                        if ((data.Grados>0) && (data.Grados<90))
                        {
                            
                            sentido="NE";
                            
                            if (data.Velocidad>5)
                            {
                                var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/cvFlecha/Encendido.png", null, "<%= ResolveUrl("~") %>Content/Images/cvFlecha/Encendido.png");
                            }
                             else if(data.Evento!=1)
                            {
                            
                                var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/emerFlecha/Emergencia.png", null, "<%= ResolveUrl("~") %>Content/Images/emerFlecha/Emergencia.png");
                            
                            }
                            else
                            {
                                var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/stopFlecha/Stop.png", null, "<%= ResolveUrl("~") %>Content/Images/stopFlecha/Stop.png");
                            }

                        }
                        if(data.Grados==90)
                        {
                        
                        sentido="E";
                       
                        if (data.Velocidad>5)
                            {
                                var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/cvFlecha/Encendido.png", null, "<%= ResolveUrl("~") %>Content/Images/cvFlecha/Encendido.png");
                            }
                             else if(data.Evento!=1)
                            {
                            
                                var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/emerFlecha/Emergencia.png", null, "<%= ResolveUrl("~") %>Content/Images/emerFlecha/Emergencia.png");
                            
                            }
                            else
                            {
                                var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/stopFlecha/Stop.png", null, "<%= ResolveUrl("~") %>Content/Images/stopFlecha/Stop.png");
                            }
                        
                        }
                        if((data.Grados>90) && (data.Grados<180))
                        {
                        
                         sentido="SE";   
                        
                          if (data.Velocidad>5)
                         {
                            var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/cvFlecha/Encendido.png", null, "<%= ResolveUrl("~") %>Content/Images/cvFlecha/Encendido.png");
                         }
                          else if(data.Evento!=1)
                            {
                            
                                var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/emerFlecha/Emergencia.png", null, "<%= ResolveUrl("~") %>Content/Images/emerFlecha/Emergencia.png");
                            
                            }
                         else
                         {
                            var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/stopFlecha/Stop.png", null, "<%= ResolveUrl("~") %>Content/Images/stopFlecha/Stop.png");
                          }  

                        }
                        if(data.Grados==180)
                        {
                        
                        sentido="S";
                        
                        if (data.Velocidad>5)
                         {
                            var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/cvFlecha/Encendido.png", null, "<%= ResolveUrl("~") %>Content/Images/cvFlecha/Encendido.png");
                        }
                         else if(data.Evento!=1)
                            {
                            
                                var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/emerFlecha/Emergencia.png", null, "<%= ResolveUrl("~") %>Content/Images/emerFlecha/Emergencia.png");
                            
                            }
                         else
                         {
                            var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/stopFlecha/Stop.png", null, "<%= ResolveUrl("~") %>Content/Images/stopFlecha/Stop.png");
                          }
                        
                        }
                        if((data.Grados>180) && (data.Grados<270))
                        {
                        
                         sentido="SW";   
                         
                          if (data.Velocidad>5)
                         {
                            var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/cvFlecha/Encendido.png", null, "<%= ResolveUrl("~") %>Content/Images/cvFlecha/Encendido.png");
                         }
                          else if(data.Evento!=1)
                            {
                            
                                var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/emerFlecha/Emergencia.png", null, "<%= ResolveUrl("~") %>Content/Images/emerFlecha/Emergencia.png");
                            
                            }
                         else
                         {
                            var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/stopFlecha/Stop.png", null, "<%= ResolveUrl("~") %>Content/Images/stopFlecha/Stop.png");
                         }

                        }
                        if(data.Grados==270)
                        {
                        
                        sentido="W";
                        
                         if (data.Velocidad>5)
                         {
                            var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/cvFlecha/Encendido.png", null, "<%= ResolveUrl("~") %>Content/Images/cvFlecha/Encendido.png");
                        }
                         else if(data.Evento!=1)
                            {
                            
                                var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/emerFlecha/Emergencia.png", null, "<%= ResolveUrl("~") %>Content/Images/emerFlecha/Emergencia.png");
                            
                            }
                         else
                         {
                            var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/stopFlecha/Stop.png", null, "<%= ResolveUrl("~") %>Content/Images/stopFlecha/Stop.png");
                            }
                        
                        }
                        if((data.Grados>270) && (data.Grados<360))
                        {
                        
                         sentido="NW";   
                         
                         if (data.Velocidad>5)
                         {
                            var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/cvFlecha/Encendido.png", null, "<%= ResolveUrl("~") %>Content/Images/cvFlecha/Encendido.png");
                         }
                          else if(data.Evento!=1)
                            {
                            
                                var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/emerFlecha/Emergencia.png", null, "<%= ResolveUrl("~") %>Content/Images/emerFlecha/Emergencia.png");
                            
                            }
                         else
                         {
                            var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/stopFlecha/Stop.png", null, "<%= ResolveUrl("~") %>Content/Images/stopFlecha/Stop.png");
                         }

                        }


                            map.setCenter(center, 7);
                            var marker = new GMarker(center,flecha);
                             map.addOverlay(marker);

                             var sentido;

                        

                             
                            //marker.openInfoWindowHtml("<b style='color: #0000FF'>POSICION ACTUAL</b><br/><b>Alias: </b><i>" + data.NombreUnidad + "</i><br/><b>Placa: </b><i>" + data.PlacaUnidad + "</i><br/><b>Fecha/Hora: </b><i>" + data.Fecha + "</i><br/><b>Velocidad: </b><i>" + data.Velocidad   +" " +"Kph</i><br/><b>Sentido: </b><i>(" + data.Grados +")"+sentido+ "</i><br/><b>Evento: </b><i>" + data.EventoNombre + "</i>");
                            GEvent.addListener(marker, "click", function () {
                            marker.openInfoWindowHtml("<b style='color: #0000FF'>POSICION ACTUAL</b><br/><b>Alias: </b><i>" +data.NombreUnidad + "</i><br/><b>Placa: </b><i>" + data.PlacaUnidad + "</i><br/><b>Fecha/Hora: </b><i>" +data.Fecha + "</i><br/><b>Velocidad: </b><i>" + data.Velocidad +" " +"Kph</i><br/><b>Sentido: </b><i>(" + data.Grados +")"+ sentido+"</i><br/><b>Evento: </b><i>" + data.EventoNombre + "</i>");
                            });//fin funcion click
                          

                                

//                                 pol[i]=center0;

                             // alert("Posicion: "+i);

                         
                         });//fir iteracion

                         //alert("pol"+pol[5]);
//                         var polyline = new GPolyline(pol, "#ff0000", 2); 
//                         map.addOverlay(polyline);
                        map.addControl(new GNavLabelControl(), new GControlPosition(G_ANCHOR_BOTTOM_RIGHT, new GSize(0, 0)));
                         map.setUIToDefault();
                         map.enableRotation();
                    }


                  


                //terminado success
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    alert("error: "+XMLHttpRequest.responseText);
                }
            });
        }

        $(window).load(function () {
            initialize();
            //GetLatLongTrack();
        });

        $(window).unload(function () {
            GUnload();
        });
    </script>
    <script type="text/javascript">
        function GetLatLong() {
          
            $.ajax({
                url: '<%= ResolveUrl("~") %>Mapa/GetLatLong',
                cache: false,
                data: 'id=' + $("#CodigoUnidad").val(),
                type: 'POST',
                success: function (data) {
                  
                    if (GBrowserIsCompatible()) {
                        var map = new GMap2(document.getElementById("map_canvas"));
                        map.setMapType(G_HYBRID_MAP);
                        map.addMapType(G_SATELLITE_3D_MAP);
                         map.addControl(new DragZoomControl());
                        geocoder = new GClientGeocoder();

                        var baseIcon = new GIcon();
                        baseIcon.iconSize = new GSize(40, 60);
                        baseIcon.shadowSize = new GSize(40, 60);
                        baseIcon.iconAnchor = new GPoint(40, 60);
                        baseIcon.infoWindowAnchor = new GPoint(16, 0);
                                               
                        var sentido;

                        if(data[6]==0)
                        {
                            sentido = "N";
                            
                            if (data[5]>5)
                            {
                                var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/cvFlecha/Encendido.png", null, "<%= ResolveUrl("~") %>Content/Images/cvFlecha/Encendido.png");
                            }
                            else if(data[7]!=1)
                            {
                            
                                var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/emerFlecha/Emergencia.png", null, "<%= ResolveUrl("~") %>Content/Images/emerFlecha/Emergencia.png");
                            
                            }
                            else
                            {
                                var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/stopFlecha/Stop.png", null, "<%= ResolveUrl("~") %>Content/Images/stopFlecha/Stop.png");
                            }
                        }
                        
                        if ((data[6]>0) && (data[6]<90))
                        {
                            
                            sentido="NE";

                            if (data[5]>5)
                            {
                                var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/cvFlecha/Encendido.png", null, "<%= ResolveUrl("~") %>Content/Images/cvFlecha/Encendido.png");
                            }
                             else if(data[7]!=1)
                            {
                            
                                var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/emerFlecha/Emergencia.png", null, "<%= ResolveUrl("~") %>Content/Images/emerFlecha/Emergencia.png");
                            
                            }
                            else
                            {
                                var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/stopFlecha/Stop.png", null, "<%= ResolveUrl("~") %>Content/Images/stopFlecha/Stop.png");
                            }
                        }
                        if(data[6]==90)
                        {
                        
                            sentido="E";
                            if (data[5]>5)
                            {
                                var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/cvFlecha/Encendido.png", null, "<%= ResolveUrl("~") %>Content/Images/cvFlecha/Encendido.png");
                            }
                             else if(data[7]!=1)
                            {
                            
                                var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/emerFlecha/Emergencia.png", null, "<%= ResolveUrl("~") %>Content/Images/emerFlecha/Emergencia.png");
                            
                            }
                            else
                            {
                                var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/stopFlecha/Stop.png", null, "<%= ResolveUrl("~") %>Content/Images/stopFlecha/Stop.png");
                            }
                        }
                        if((data[6]>90) && (data[6]<180))
                        {
                        
                         sentido="SE";   
                         if (data[5]>5)
                         {
                            var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/cvFlecha/Encendido.png", null, "<%= ResolveUrl("~") %>Content/Images/cvFlecha/Encendido.png");
                         }
                          else if(data[7]!=1)
                            {
                            
                                var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/emerFlecha/Emergencia.png", null, "<%= ResolveUrl("~") %>Content/Images/emerFlecha/Emergencia.png");
                            
                            }
                         else
                         {
                            var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/stopFlecha/Stop.png", null, "<%= ResolveUrl("~") %>Content/Images/stopFlecha/Stop.png");
                          }  
                        }
                        if(data[6]==180)
                        {
                        
                        sentido="S";
                         if (data[5]>5)
                         {
                            var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/cvFlecha/Encendido.png", null, "<%= ResolveUrl("~") %>Content/Images/cvFlecha/Encendido.png");
                        }
                         else if(data[7]!=1)
                            {
                            
                                var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/emerFlecha/Emergencia.png", null, "<%= ResolveUrl("~") %>Content/Images/emerFlecha/Emergencia.png");
                            
                            }
                         else
                         {
                            var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/stopFlecha/Stop.png", null, "<%= ResolveUrl("~") %>Content/Images/stopFlecha/Stop.png");
                          }
                        }
                        if((data[6]>180) && (data[6]<270))
                        {
                        
                         sentido="SW";   
                         if (data[5]>5)
                         {
                            var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/cvFlecha/Encendido.png", null, "<%= ResolveUrl("~") %>Content/Images/cvFlecha/Encendido.png");
                         }
                         else if(data[7]!=1)
                            {
                            
                                var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/emerFlecha/Emergencia.png", null, "<%= ResolveUrl("~") %>Content/Images/emerFlecha/Emergencia.png");
                            
                            }
                         else
                         {
                            var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/stopFlecha/Stop.png", null, "<%= ResolveUrl("~") %>Content/Images/stopFlecha/Stop.png");
                         }
                        }
                        if(data[6]==270)
                        {
                        
                        sentido="W";
                         if (data[5]>5)
                         {
                            var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/cvFlecha/Encendido.png", null, "<%= ResolveUrl("~") %>Content/Images/cvFlecha/Encendido.png");
                        }
                         else if(data[7]!=1)
                            {
                            
                                var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/emerFlecha/Emergencia.png", null, "<%= ResolveUrl("~") %>Content/Images/emerFlecha/Emergencia.png");
                            
                            }
                         else
                         {
                            var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/stopFlecha/Stop.png", null, "<%= ResolveUrl("~") %>Content/Images/stopFlecha/Stop.png");
                            }
                        }
                        if((data[6]>270) && (data[6]<360))
                        {
                        
                         sentido="NW";   
                         if (data[5]>5)
                         {
                            var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/cvFlecha/Encendido.png", null, "<%= ResolveUrl("~") %>Content/Images/cvFlecha/Encendido.png");
                         }
                          else if(data[7]!=1)
                            {
                            
                                var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/emerFlecha/Emergencia.png", null, "<%= ResolveUrl("~") %>Content/Images/emerFlecha/Emergencia.png");
                            
                            }
                         else
                         {
                            var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/stopFlecha/Stop.png", null, "<%= ResolveUrl("~") %>Content/Images/stopFlecha/Stop.png");
                         }
                        }

                        var center = new GLatLng(data[0], data[1]);
                        map.setCenter(center, 18);
                        var marker = new GMarker(center,flecha);
                        map.setUIToDefault();
                        map.enableRotation();
                        map.addControl(new GNavLabelControl(), new GControlPosition(G_ANCHOR_BOTTOM_RIGHT, new GSize(0, 0)));
                        map.addOverlay(marker);
                       


                        //marker.openInfoWindowHtml("<b style='color: #0000FF'>ULTIMA UBICACION VALIDA</b><br/><b>Alias: </b><i>" + data[3] + "</i><br/><b>Placa: </b><i>" + data[4] + "</i><br/><b>Fecha/Hora: </b><i>" + data[2] + "</i><br/><b>Velocidad: </b><i>" + data[5] +" " +"Kph</i><br/><b>Sentido: </b><i>(" + data[6] + ")"+sentido+"</i><br/><b>Evento: </b><i>" + data[8] + "</i><br/><a href='../Mapa/BusquedaPorPosicion'>Ubicacion</a><br/><a href='../Mapa/BusquedaPorPosicion'>Sensores I/O</a>");
                        GEvent.addListener(marker, "click", function () {
                            marker.openInfoWindowHtml("<b style='color: #0000FF'>ULTIMA UBICACION VALIDA</b><br/><b>Alias: </b><i>" + data[3] + "</i><br/><b>Placa: </b><i>" + data[4] + "</i><br/><b>Fecha/Hora: </b><i>" + data[2] + "</i><br/><b>Velocidad: </b><i>" + data[5] +" " +"Kph</i><br/><b>Sentido: </b><i>(" + data[6] + ")"+sentido+"</i><br/><b>Evento: </b><i>" + data[8] + "</i><br/><a href='../Mapa/BusquedaPorPosicion'>Ubicacion</a><br/><a href='../Mapa/BusquedaPorPosicion'>Sensores I/O</a>");
                        });
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    $("#error").html(XMLHttpRequest.responseText);
                }
            });
        }
    </script>
    <script type="text/javascript">
      

        function GetLatLongTrack(mapa) {
                
                if (mapa==1)
                {
                
                    var mapaTipo=G_HYBRID_MAP;
                }
                else if (mapa==2)
                {
                    var mapaTipo=G_SATELLITE_3D_MAP;
                  
                }else
                {
                
                    var mapaTipo=G_NORMAL_MAP;
                    
                }


                $.ajax({
                type: "POST",
                url: "<%= ResolveUrl("~") %>Mapa/GetLatLong",
                data: 'id=' + $("#CodigoUnidad").val(),
                dataType: "json",
                cache: false,
                success: function (response) {
                    //alert("entre suscces");

                    if (GBrowserIsCompatible()) {
                        var map = new GMap2(document.getElementById("map_canvas"));
                        map.setMapType(mapaTipo);
                         //map.addMapType(G_SATELLITE_3D_MAP);
                         //map.setMapType(G_SATELLITE_3D_MAP);
                        //google.earth.createInstance("map_canvas", initCallback, failureCallback);//

                       
                         map.addControl(new DragZoomControl());
                        var baseIcon = new GIcon();
                        baseIcon.iconSize = new GSize(40, 60);
                        baseIcon.shadowSize = new GSize(40, 60);
                        baseIcon.iconAnchor = new GPoint(40, 60);
                        baseIcon.infoWindowAnchor = new GPoint(16, 0);
                        
                        var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/Flechas-180.gif", null, "<%= ResolveUrl("~") %>Content/Images/Flechas-180s.gif");
                                               
                        var center0=new GLatLng();
                        var pol = new Array();
                        var contador = 0;

                         $.each(response, function(i, data) {

                            if( contador == 0 ) {
                                $('#startelmaps').attr('href', '<%= ResolveUrl("~") %>Mapa/Startelmaps/?lon=' + data.Longitud + 
                                    '&lat=' + data.Latitud + '&nom=' + data.NombreUnidad + 
                                    '&pla=' + data.PlacaUnidad + '&vel=' + data.Velocidad + 
                                    '&fch=' + data.Fecha);
                            }

                            contador ++;

                           //alert (center1);
                            var center = new GLatLng(data.Latitud, data.Longitud);
                            var center0=center;
                           
                            if(data.Grados==0)
                        {
                            sentido="N";

                            if (data.Velocidad>5)
                            {
                                var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/cvFlecha/Encendido.png", null, "<%= ResolveUrl("~") %>Content/Images/cvFlecha/Encendido.png");
                            }
                             else if(data.Evento!=1)
                            {
                            
                                var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/emerFlecha/Emergencia.png", null, "<%= ResolveUrl("~") %>Content/Images/emerFlecha/Emergencia.png");
                            
                            }
                            else
                            {
                                var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/stopFlecha/Stop.png", null, "<%= ResolveUrl("~") %>Content/Images/stopFlecha/Stop.png");
                            }
                        }
                        
                        if ((data.Grados>0) && (data.Grados<90))
                        {
                            
                            sentido="NE";
                            
                            if (data.Velocidad>5)
                            {
                                var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/cvFlecha/Encendido.png", null, "<%= ResolveUrl("~") %>Content/Images/cvFlecha/Encendido.png");
                            }
                             else if(data.Evento!=1)
                            {
                            
                                var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/emerFlecha/Emergencia.png", null, "<%= ResolveUrl("~") %>Content/Images/emerFlecha/Emergencia.png");
                            
                            }
                            else
                            {
                                var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/stopFlecha/Stop.png", null, "<%= ResolveUrl("~") %>Content/Images/stopFlecha/Stop.png");
                            }

                        }
                        if(data.Grados==90)
                        {
                        
                        sentido="E";
                       
                        if (data.Velocidad>5)
                            {
                                var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/cvFlecha/Encendido.png", null, "<%= ResolveUrl("~") %>Content/Images/cvFlecha/Encendido.png");
                            }
                             else if(data.Evento!=1)
                            {
                            
                                var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/emerFlecha/Emergencia.png", null, "<%= ResolveUrl("~") %>Content/Images/emerFlecha/Emergencia.png");
                            
                            }
                            else
                            {
                                var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/stopFlecha/Stop.png", null, "<%= ResolveUrl("~") %>Content/Images/stopFlecha/Stop.png");
                            }
                        
                        }
                        if((data.Grados>90) && (data.Grados<180))
                        {
                        
                         sentido="SE";   
                        
                          if (data.Velocidad>5)
                         {
                            var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/cvFlecha/Encendido.png", null, "<%= ResolveUrl("~") %>Content/Images/cvFlecha/Encendido.png");
                         }
                          else if(data.Evento!=1)
                            {
                            
                                var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/emerFlecha/Emergencia.png", null, "<%= ResolveUrl("~") %>Content/Images/emerFlecha/Emergencia.png");
                            
                            }
                         else
                         {
                            var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/stopFlecha/Stop.png", null, "<%= ResolveUrl("~") %>Content/Images/stopFlecha/Stop.png");
                          }  

                        }
                        if(data.Grados==180)
                        {
                        
                        sentido="S";
                        
                        if (data.Velocidad>5)
                         {
                            var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/cvFlecha/Encendido.png", null, "<%= ResolveUrl("~") %>Content/Images/cvFlecha/Encendido.png");
                        }
                         else if(data.Evento!=1)
                            {
                            
                                var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/emerFlecha/Emergencia.png", null, "<%= ResolveUrl("~") %>Content/Images/emerFlecha/Emergencia.png");
                            
                            }
                         else
                         {
                            var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/stopFlecha/Stop.png", null, "<%= ResolveUrl("~") %>Content/Images/stopFlecha/Stop.png");
                          }
                        
                        }
                        if((data.Grados>180) && (data.Grados<270))
                        {
                        
                         sentido="SW";   
                         
                          if (data.Velocidad>5)
                         {
                            var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/cvFlecha/Encendido.png", null, "<%= ResolveUrl("~") %>Content/Images/cvFlecha/Encendido.png");
                         }
                          else if(data.Evento!=1)
                            {
                            
                                var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/emerFlecha/Emergencia.png", null, "<%= ResolveUrl("~") %>Content/Images/emerFlecha/Emergencia.png");
                            
                            }
                         else
                         {
                            var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/stopFlecha/Stop.png", null, "<%= ResolveUrl("~") %>Content/Images/stopFlecha/Stop.png");
                         }

                        }
                        if(data.Grados==270)
                        {
                        
                        sentido="W";
                        
                         if (data.Velocidad>5)
                         {
                            var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/cvFlecha/Encendido.png", null, "<%= ResolveUrl("~") %>Content/Images/cvFlecha/Encendido.png");
                        }
                         else if(data.Evento!=1)
                            {
                            
                                var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/emerFlecha/Emergencia.png", null, "<%= ResolveUrl("~") %>Content/Images/emerFlecha/Emergencia.png");
                            
                            }
                         else
                         {
                            var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/stopFlecha/Stop.png", null, "<%= ResolveUrl("~") %>Content/Images/stopFlecha/Stop.png");
                            }
                        
                        }
                        if((data.Grados>270) && (data.Grados<360))
                        {
                        
                         sentido="NW";   
                         
                         if (data.Velocidad>5)
                         {
                            var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/cvFlecha/Encendido.png", null, "<%= ResolveUrl("~") %>Content/Images/cvFlecha/Encendido.png");
                         }
                          else if(data.Evento!=1)
                            {
                            
                                var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/emerFlecha/Emergencia.png", null, "<%= ResolveUrl("~") %>Content/Images/emerFlecha/Emergencia.png");
                            
                            }
                         else
                         {
                            var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/stopFlecha/Stop.png", null, "<%= ResolveUrl("~") %>Content/Images/stopFlecha/Stop.png");
                         }

                        }


                            map.setCenter(center, 10);
                            var marker = new GMarker(center,flecha);
                             map.addOverlay(marker);

                             var sentido;

                        

                             
                           // marker.openInfoWindowHtml("<b style='color: #0000FF'>POSICION "+ i +"</b><br/><b>Alias: </b><i>" + data.NombreUnidad + "</i><br/><b>Placa: </b><i>" + data.PlacaUnidad + "</i><br/><b>Fecha/Hora: </b><i>" + data.Fecha + "</i><br/><b>Velocidad: </b><i>" + data.Velocidad   +" " +"Kph</i><br/><b>Sentido: </b><i>(" + data.Grados +")"+sentido+ "</i><br/><b>Evento: </b><i>" + data.EventoNombre + "</i>");
                            GEvent.addListener(marker, "click", function () {
                            marker.openInfoWindowHtml("<b style='color: #0000FF'>POSICION "+ i +"</b><br/><b>Alias: </b><i>" +data.NombreUnidad + "</i><br/><b>Placa: </b><i>" + data.PlacaUnidad + "</i><br/><b>Fecha/Hora: </b><i>" +data.Fecha + "</i><br/><b>Velocidad: </b><i>" + data.Velocidad +" " +"Kph</i><br/><b>Sentido: </b><i>(" + data.Grados +")"+ sentido+"</i><br/><b>Evento: </b><i>" + data.EventoNombre + "</i>");
                            });//fin funcion click
                          

                                

                                 pol[i]=center0;

                              //alert("Posicion: "+i);

                         
                         });//fir iteracion


                         //alert("pol"+pol[0]);
                         
                         map.setCenter(pol[0], 17);
//                         var marker = new GMarker(pol[0],flecha);
//                         map.addOverlay(marker);
//                          GEvent.addListener(marker, "click", function () {
//                            marker.openInfoWindowHtml("<b style='color: #0000FF'>POSICION 0 </b><br/><b>Alias: </b><i>" +data.NombreUnidad + "</i><br/><b>Placa: </b><i>" + data.PlacaUnidad + "</i><br/><b>Fecha/Hora: </b><i>" +data.Fecha + "</i><br/><b>Velocidad: </b><i>" + data.Velocidad +" " +"Kph</i><br/><b>Sentido: </b><i>(" + data.Grados +")"+ sentido+"</i><br/><b>Evento: </b><i>" + data.EventoNombre + "</i>");
//                            });

                         var polyline = new GPolyline(pol, "#ff0000", 2); 
                         map.addOverlay(polyline);
                         map.addControl(new GNavLabelControl(), new GControlPosition(G_ANCHOR_BOTTOM_RIGHT, new GSize(0, 0)));
                         map.setUIToDefault();
                         map.enableRotation();
                    }


                  


                //terminado success
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    //alert("error: "+XMLHttpRequest.responseText);
                }
            });


        }

       

        function GetLatLongTrackTodas(mapa) {
            
            if (mapa==1)
                {
                
                    var mapaTipo=G_HYBRID_MAP;
                }
                else if (mapa==2)
                {
                    var mapaTipo=G_SATELLITE_3D_MAP;
                  
                }else
                {
                
                    var mapaTipo=G_NORMAL_MAP;
                    
                }
            
                
                $.ajax({
                type: "POST",
                url: "<%= ResolveUrl("~") %>Mapa/GetLatLong",
                data: 'id=' + $("#CodigoUnidad").val(),
                dataType: "json",
                cache: false,
                success: function (response) {
                    //alert("entre suscces");

                    if (GBrowserIsCompatible()) {
                        var map = new GMap2(document.getElementById("map_canvas"));
                        map.setMapType(mapaTipo);
                        //map.addMapType(G_SATELLITE_3D_MAP);
                         map.addControl(new DragZoomControl());
                        var baseIcon = new GIcon();
                        baseIcon.iconSize = new GSize(40, 60);
                        baseIcon.shadowSize = new GSize(40, 60);
                        baseIcon.iconAnchor = new GPoint(40, 60);
                        baseIcon.infoWindowAnchor = new GPoint(16, 0);
                        //var edificio = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/CabrioletRedblanco.png", null, "<%= ResolveUrl("~") %>Content/Images/CabrioletRedblancos.png");
                        var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/Flechas-180.gif", null, "<%= ResolveUrl("~") %>Content/Images/Flechas-180s.gif");
                        
                        //var center = new GLatLng(data[0], data[1]);
                        var center0=new GLatLng();
                        var pol = new Array();
                        var contador = 0;

                         $.each(response, function(i, data) {

                            if( contador == 0 ) {
                                $('#startelmaps').attr('href', '<%= ResolveUrl("~") %>Mapa/Startelmaps/?lon=' + data.Longitud + 
                                    '&lat=' + data.Latitud + '&nom=' + data.NombreUnidad + 
                                    '&pla=' + data.PlacaUnidad + '&vel=' + data.Velocidad + 
                                    '&fch=' + data.Fecha);
                            }

                            contador ++;

                           //alert (center1);
                            var center = new GLatLng(data.Latitud, data.Longitud);
                            var center0=center;
                           
                            if(data.Grados==0)
                        {
                            sentido="N";

                            if (data.Velocidad>5)
                            {
                                var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/cvFlecha/Encendido.png", null, "<%= ResolveUrl("~") %>Content/Images/cvFlecha/Encendido.png");
                            }
                             else if(data.Evento!=1)
                            {
                            
                                var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/emerFlecha/Emergencia.png", null, "<%= ResolveUrl("~") %>Content/Images/emerFlecha/Emergencia.png");
                            
                            }
                            else
                            {
                                var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/stopFlecha/Stop.png", null, "<%= ResolveUrl("~") %>Content/Images/stopFlecha/Stop.png");
                            }
                        }
                        
                        if ((data.Grados>0) && (data.Grados<90))
                        {
                            
                            sentido="NE";
                            
                            if (data.Velocidad>5)
                            {
                                var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/cvFlecha/Encendido.png", null, "<%= ResolveUrl("~") %>Content/Images/cvFlecha/Encendido.png");
                            }
                             else if(data.Evento!=1)
                            {
                            
                                var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/emerFlecha/Emergencia.png", null, "<%= ResolveUrl("~") %>Content/Images/emerFlecha/Emergencia.png");
                            
                            }
                            else
                            {
                                var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/stopFlecha/Stop.png", null, "<%= ResolveUrl("~") %>Content/Images/stopFlecha/Stop.png");
                            }

                        }
                        if(data.Grados==90)
                        {
                        
                        sentido="E";
                       
                        if (data.Velocidad>5)
                            {
                                var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/cvFlecha/Encendido.png", null, "<%= ResolveUrl("~") %>Content/Images/cvFlecha/Encendido.png");
                            }
                             else if(data.Evento!=1)
                            {
                            
                                var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/emerFlecha/Emergencia.png", null, "<%= ResolveUrl("~") %>Content/Images/emerFlecha/Emergencia.png");
                            
                            }
                            else
                            {
                                var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/stopFlecha/Stop.png", null, "<%= ResolveUrl("~") %>Content/Images/stopFlecha/Stop.png");
                            }
                        
                        }
                        if((data.Grados>90) && (data.Grados<180))
                        {
                        
                         sentido="SE";   
                        
                          if (data.Velocidad>5)
                         {
                            var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/cvFlecha/Encendido.png", null, "<%= ResolveUrl("~") %>Content/Images/cvFlecha/Encendido.png");
                         }
                          else if(data.Evento!=1)
                            {
                            
                                var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/emerFlecha/Emergencia.png", null, "<%= ResolveUrl("~") %>Content/Images/emerFlecha/Emergencia.png");
                            
                            }
                         else
                         {
                            var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/stopFlecha/Stop.png", null, "<%= ResolveUrl("~") %>Content/Images/stopFlecha/Stop.png");
                          }  

                        }
                        if(data.Grados==180)
                        {
                        
                        sentido="S";
                        
                        if (data.Velocidad>5)
                         {
                            var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/cvFlecha/Encendido.png", null, "<%= ResolveUrl("~") %>Content/Images/cvFlecha/Encendido.png");
                        }
                         else if(data.Evento!=1)
                            {
                            
                                var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/emerFlecha/Emergencia.png", null, "<%= ResolveUrl("~") %>Content/Images/emerFlecha/Emergencia.png");
                            
                            }
                         else
                         {
                            var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/stopFlecha/Stop.png", null, "<%= ResolveUrl("~") %>Content/Images/stopFlecha/Stop.png");
                          }
                        
                        }
                        if((data.Grados>180) && (data.Grados<270))
                        {
                        
                         sentido="SW";   
                         
                          if (data.Velocidad>5)
                         {
                            var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/cvFlecha/Encendido.png", null, "<%= ResolveUrl("~") %>Content/Images/cvFlecha/Encendido.png");
                         }
                          else if(data.Evento!=1)
                            {
                            
                                var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/emerFlecha/Emergencia.png", null, "<%= ResolveUrl("~") %>Content/Images/emerFlecha/Emergencia.png");
                            
                            }
                         else
                         {
                            var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/stopFlecha/Stop.png", null, "<%= ResolveUrl("~") %>Content/Images/stopFlecha/Stop.png");
                         }

                        }
                        if(data.Grados==270)
                        {
                        
                        sentido="W";
                        
                         if (data.Velocidad>5)
                         {
                            var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/cvFlecha/Encendido.png", null, "<%= ResolveUrl("~") %>Content/Images/cvFlecha/Encendido.png");
                        }
                         else if(data.Evento!=1)
                            {
                            
                                var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/emerFlecha/Emergencia.png", null, "<%= ResolveUrl("~") %>Content/Images/emerFlecha/Emergencia.png");
                            
                            }
                         else
                         {
                            var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/stopFlecha/Stop.png", null, "<%= ResolveUrl("~") %>Content/Images/stopFlecha/Stop.png");
                            }
                        
                        }
                        if((data.Grados>270) && (data.Grados<360))
                        {
                        
                         sentido="NW";   
                         
                         if (data.Velocidad>5)
                         {
                            var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/cvFlecha/Encendido.png", null, "<%= ResolveUrl("~") %>Content/Images/cvFlecha/Encendido.png");
                         }
                          else if(data.Evento!=1)
                            {
                            
                                var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/emerFlecha/Emergencia.png", null, "<%= ResolveUrl("~") %>Content/Images/emerFlecha/Emergencia.png");
                            
                            }
                         else
                         {
                            var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/stopFlecha/Stop.png", null, "<%= ResolveUrl("~") %>Content/Images/stopFlecha/Stop.png");
                         }

                        }


                            map.setCenter(center, 7);
                            var marker = new GMarker(center,flecha);
                             map.addOverlay(marker);

                             var sentido;

                        

                             
                           // marker.openInfoWindowHtml("<b style='color: #0000FF'>POSICION "+ i +"</b><br/><b>Alias: </b><i>" + data.NombreUnidad + "</i><br/><b>Placa: </b><i>" + data.PlacaUnidad + "</i><br/><b>Fecha/Hora: </b><i>" + data.Fecha + "</i><br/><b>Velocidad: </b><i>" + data.Velocidad   +" " +"Kph</i><br/><b>Sentido: </b><i>(" + data.Grados +")"+sentido+ "</i><br/><b>Evento: </b><i>" + data.EventoNombre + "</i>");
                            GEvent.addListener(marker, "click", function () {
                            marker.openInfoWindowHtml("<b style='color: #0000FF'>POSICION "+ i +"</b><br/><b>Alias: </b><i>" +data.NombreUnidad + "</i><br/><b>Placa: </b><i>" + data.PlacaUnidad + "</i><br/><b>Fecha/Hora: </b><i>" +data.Fecha + "</i><br/><b>Velocidad: </b><i>" + data.Velocidad +" " +"Kph</i><br/><b>Sentido: </b><i>(" + data.Grados +")"+ sentido+"</i><br/><b>Evento: </b><i>" + data.EventoNombre + "</i>");
                            });//fin funcion click
                          

                                

                                 pol[i]=center0;

                              //alert("Posicion: "+i);

                         
                         });//fir iteracion


                         //alert("pol"+pol[0]);
                         
                         map.setCenter(pol[0], 7);
                         

//                         var polyline = new GPolyline(pol, "#ff0000", 2); 
//                         map.addOverlay(polyline);
                        map.addControl(new GNavLabelControl(), new GControlPosition(G_ANCHOR_BOTTOM_RIGHT, new GSize(0, 0)));
                         map.setUIToDefault();
                         map.enableRotation();
                    }


                  


                //terminado success
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    //alert("error: "+XMLHttpRequest.responseText);
                }
            });


        }
         function GetLatLongTrackGrupo(mapa) {
            
              if (mapa==1)
                {
                
                    var mapaTipo=G_HYBRID_MAP;
                }
                else if (mapa==2)
                {
                    var mapaTipo=G_SATELLITE_3D_MAP;
                  
                }else
                {
                
                    var mapaTipo=G_NORMAL_MAP;
                    
                }
            
                
                $.ajax({
                type: "POST",
                url: "<%= ResolveUrl("~") %>Mapa/GetLatLongGrupos",
                data: 'codigoGrupo=' + $("#Grupos").val(),
                dataType: "json",
                cache: false,
                success: function (response) {
                    //alert("entre suscces");

                    if (GBrowserIsCompatible()) {
                        var map = new GMap2(document.getElementById("map_canvas"));
                        map.setMapType(mapaTipo);
                        //map.addMapType(G_SATELLITE_3D_MAP);
                         map.addControl(new DragZoomControl());
                        var baseIcon = new GIcon();
                        baseIcon.iconSize = new GSize(40, 60);
                        baseIcon.shadowSize = new GSize(40, 60);
                        baseIcon.iconAnchor = new GPoint(40, 60);
                        baseIcon.infoWindowAnchor = new GPoint(16, 0);
                        //var edificio = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/CabrioletRedblanco.png", null, "<%= ResolveUrl("~") %>Content/Images/CabrioletRedblancos.png");
                        var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/Flechas-180.gif", null, "<%= ResolveUrl("~") %>Content/Images/Flechas-180s.gif");
                        
                        //var center = new GLatLng(data[0], data[1]);
                        var center0=new GLatLng();
                        var pol = new Array();
                        var contador = 0;

                         $.each(response, function(i, data) {

                            if( contador == 0 ) {
                                $('#startelmaps').attr('href', '<%= ResolveUrl("~") %>Mapa/Startelmaps/?lon=' + data.Longitud + 
                                    '&lat=' + data.Latitud + '&nom=' + data.NombreUnidad + 
                                    '&pla=' + data.PlacaUnidad + '&vel=' + data.Velocidad + 
                                    '&fch=' + data.Fecha);
                            }

                            contador ++;

                           //alert (center1);
                            var center = new GLatLng(data.Latitud, data.Longitud);
                            var center0=center;
                           
                            if(data.Grados==0)
                        {
                            sentido="N";

                            if (data.Velocidad>5)
                            {
                                var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/cvFlecha/Encendido.png", null, "<%= ResolveUrl("~") %>Content/Images/cvFlecha/Encendido.png");
                            }
                             else if(data.Evento!=1)
                            {
                            
                                var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/emerFlecha/Emergencia.png", null, "<%= ResolveUrl("~") %>Content/Images/emerFlecha/Emergencia.png");
                            
                            }
                            else
                            {
                                var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/stopFlecha/Stop.png", null, "<%= ResolveUrl("~") %>Content/Images/stopFlecha/Stop.png");
                            }
                        }
                        
                        if ((data.Grados>0) && (data.Grados<90))
                        {
                            
                            sentido="NE";
                            
                            if (data.Velocidad>5)
                            {
                                var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/cvFlecha/Encendido.png", null, "<%= ResolveUrl("~") %>Content/Images/cvFlecha/Encendido.png");
                            }
                             else if(data.Evento!=1)
                            {
                            
                                var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/emerFlecha/Emergencia.png", null, "<%= ResolveUrl("~") %>Content/Images/emerFlecha/Emergencia.png");
                            
                            }
                            else
                            {
                                var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/stopFlecha/Stop.png", null, "<%= ResolveUrl("~") %>Content/Images/stopFlecha/Stop.png");
                            }

                        }
                        if(data.Grados==90)
                        {
                        
                        sentido="E";
                       
                        if (data.Velocidad>5)
                            {
                                var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/cvFlecha/Encendido.png", null, "<%= ResolveUrl("~") %>Content/Images/cvFlecha/Encendido.png");
                            }
                             else if(data.Evento!=1)
                            {
                            
                                var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/emerFlecha/Emergencia.png", null, "<%= ResolveUrl("~") %>Content/Images/emerFlecha/Emergencia.png");
                            
                            }
                            else
                            {
                                var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/stopFlecha/Stop.png", null, "<%= ResolveUrl("~") %>Content/Images/stopFlecha/Stop.png");
                            }
                        
                        }
                        if((data.Grados>90) && (data.Grados<180))
                        {
                        
                         sentido="SE";   
                        
                          if (data.Velocidad>5)
                         {
                            var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/cvFlecha/Encendido.png", null, "<%= ResolveUrl("~") %>Content/Images/cvFlecha/Encendido.png");
                         }
                          else if(data.Evento!=1)
                            {
                            
                                var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/emerFlecha/Emergencia.png", null, "<%= ResolveUrl("~") %>Content/Images/emerFlecha/Emergencia.png");
                            
                            }
                         else
                         {
                            var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/stopFlecha/Stop.png", null, "<%= ResolveUrl("~") %>Content/Images/stopFlecha/Stop.png");
                          }  

                        }
                        if(data.Grados==180)
                        {
                        
                        sentido="S";
                        
                        if (data.Velocidad>5)
                         {
                            var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/cvFlecha/Encendido.png", null, "<%= ResolveUrl("~") %>Content/Images/cvFlecha/Encendido.png");
                        }
                         else if(data.Evento!=1)
                            {
                            
                                var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/emerFlecha/Emergencia.png", null, "<%= ResolveUrl("~") %>Content/Images/emerFlecha/Emergencia.png");
                            
                            }
                         else
                         {
                            var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/stopFlecha/Stop.png", null, "<%= ResolveUrl("~") %>Content/Images/stopFlecha/Stop.png");
                          }
                        
                        }
                        if((data.Grados>180) && (data.Grados<270))
                        {
                        
                         sentido="SW";   
                         
                          if (data.Velocidad>5)
                         {
                            var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/cvFlecha/Encendido.png", null, "<%= ResolveUrl("~") %>Content/Images/cvFlecha/Encendido.png");
                         }
                          else if(data.Evento!=1)
                            {
                            
                                var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/emerFlecha/Emergencia.png", null, "<%= ResolveUrl("~") %>Content/Images/emerFlecha/Emergencia.png");
                            
                            }
                         else
                         {
                            var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/stopFlecha/Stop.png", null, "<%= ResolveUrl("~") %>Content/Images/stopFlecha/Stop.png");
                         }

                        }
                        if(data.Grados==270)
                        {
                        
                        sentido="W";
                        
                         if (data.Velocidad>5)
                         {
                            var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/cvFlecha/Encendido.png", null, "<%= ResolveUrl("~") %>Content/Images/cvFlecha/Encendido.png");
                        }
                         else if(data.Evento!=1)
                            {
                            
                                var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/emerFlecha/Emergencia.png", null, "<%= ResolveUrl("~") %>Content/Images/emerFlecha/Emergencia.png");
                            
                            }
                         else
                         {
                            var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/stopFlecha/Stop.png", null, "<%= ResolveUrl("~") %>Content/Images/stopFlecha/Stop.png");
                            }
                        
                        }
                        if((data.Grados>270) && (data.Grados<360))
                        {
                        
                         sentido="NW";   
                         
                         if (data.Velocidad>5)
                         {
                            var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/cvFlecha/Encendido.png", null, "<%= ResolveUrl("~") %>Content/Images/cvFlecha/Encendido.png");
                         }
                          else if(data.Evento!=1)
                            {
                            
                                var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/emerFlecha/Emergencia.png", null, "<%= ResolveUrl("~") %>Content/Images/emerFlecha/Emergencia.png");
                            
                            }
                         else
                         {
                            var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/stopFlecha/Stop.png", null, "<%= ResolveUrl("~") %>Content/Images/stopFlecha/Stop.png");
                         }

                        }


                            map.setCenter(center, 7);
                            var marker = new GMarker(center,flecha);
                             map.addOverlay(marker);

                             var sentido;

                        

                             
                            //marker.openInfoWindowHtml("<b style='color: #0000FF'>POSICION ACTUAL</b><br/><b>Alias: </b><i>" + data.NombreUnidad + "</i><br/><b>Placa: </b><i>" + data.PlacaUnidad + "</i><br/><b>Fecha/Hora: </b><i>" + data.Fecha + "</i><br/><b>Velocidad: </b><i>" + data.Velocidad   +" " +"Kph</i><br/><b>Sentido: </b><i>(" + data.Grados +")"+sentido+ "</i><br/><b>Evento: </b><i>" + data.EventoNombre + "</i>");
                            GEvent.addListener(marker, "click", function () {
                            marker.openInfoWindowHtml("<b style='color: #0000FF'>POSICION ACTUAL</b><br/><b>Alias: </b><i>" +data.NombreUnidad + "</i><br/><b>Placa: </b><i>" + data.PlacaUnidad + "</i><br/><b>Fecha/Hora: </b><i>" +data.Fecha + "</i><br/><b>Velocidad: </b><i>" + data.Velocidad +" " +"Kph</i><br/><b>Sentido: </b><i>(" + data.Grados +")"+ sentido+"</i><br/><b>Evento: </b><i>" + data.EventoNombre + "</i>");
                            });//fin funcion click
                          

                                

//                                 pol[i]=center0;

                             // alert("Posicion: "+i);

                         
                         });//fir iteracion

                         //alert("pol"+pol[5]);
//                         var polyline = new GPolyline(pol, "#ff0000", 2); 
//                         map.addOverlay(polyline);
                        map.addControl(new GNavLabelControl(), new GControlPosition(G_ANCHOR_BOTTOM_RIGHT, new GSize(0, 0)));
                         map.setUIToDefault();
                         map.enableRotation();
                    }


                  


                //terminado success
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    alert("error: "+XMLHttpRequest.responseText);
                }
            });


        }
    </script>
    <script type="text/javascript">

        function mostrar() {
            alert($("#mostrar").val());
        }
    </script>
</asp:Content>
